<?php
$params = array_merge(
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-api',
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\controllers',
    'bootstrap' => [
        [
            'class' => 'yii\filters\ContentNegotiator',
            'formats' => [
                'application/json' => 'json',
                'application/xml' => 'html',
                'application/html' => 'html',
                'text/html' => 'html',
            ],
            'languages' => [
                'zh-CN',
                'en',
            ],
        ],
        'log',
    ],
    'components' => [
        'user' => [
            'identityClass' => 'api\models\User',
            'enableAutoLogin' => false,
            'loginUrl' => null,
            'enableSession' => false,
        ],
        'session' => [
            'name' => 'advanced-api',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','info'],
                ],
            ],
        ],

        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => false,
            'showScriptName' => false,
            'rules' => [
                // User restfull
                ['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
                //模块化的路径
                "GET,POST,PUT,DELETE <module:[\w-]+>/<controller:[\w-]+>/<action:[\w-]+>" => "<module>/<controller>/<action>",
                //基本路径
                "GET,POST,PUT,DELETE <controller:[\w-]+>/<action:[\w-]+>" => "<controller>/<action>",
            ],
        ],
        'request' => [
            'class' => '\yii\web\Request',
            'enableCookieValidation' => true,
            'csrfParam' => '_csrf-api',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                'text/json' => 'yii\web\JsonParser',
            ],
        ],
        'response' => [
            'class' => '\yii\web\Response',
            'charset' => 'UTF-8',
            //返回异常统一处理
            'on beforeSend' => function ($event) {
                //$event->sender->format = 'json';

            },
        ],
    ],
    'params' => $params,
];
